<?php

/**
 * The header for our theme
 *
 * This is the template that displays all of the <head> section and everything up until <div id="content">
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package WordPress
 * @subpackage Twenty_Seventeen
 * @since 1.0
 * @version 1.0
 */

?>
<!DOCTYPE html>
<html <?php language_attributes(); ?> class="no-js no-svg">

<head>
    <meta charset="<?php bloginfo('charset'); ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="profile" href="http://gmpg.org/xfn/11">

    <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
    <?php wp_body_open(); ?>
    <div id="page" class="site">
        <a class="skip-link screen-reader-text" href="#content"><?php _e('Skip to content', 'twentyseventeen'); ?></a>

        <header id="masthead" class="site-header wrap" role="banner">

            <?php
            //get_template_part( 'template-parts/header/header', 'image' ); 
            //get_template_part( 'template-parts/header/site', 'branding' ); 
            ?>

            <?php if (has_nav_menu('top')) : ?>
                <div class="navigation-top">
                    <div class="wrap">
                        <div class="top-logo"><a href="/">&nbsp;</a></div>
                        <?php get_template_part('template-parts/navigation/navigation', 'top'); ?>
                    </div><!-- .wrap -->
                </div><!-- .navigation-top -->
            <?php endif; ?>

        </header><!-- #masthead -->

        <?php
        $bannerConf = esc_attr(get_option('ttty_banner_conf'));
        if(!empty($bannerConf)) {
            $bannerConf = explode(PHP_EOL, $bannerConf);
        } else {
            $bannerConf = [
                get_theme_file_uri('/assets/images/banner1.jpg'),
                get_theme_file_uri('/assets/images/banner2.jpg'),
                get_theme_file_uri('/assets/images/banner3.jpg'),
                get_theme_file_uri('/assets/images/banner4.jpg'),
            ];
        }
        ?>

        <?php if (is_home() || is_front_page()) : ?>
            <link rel="stylesheet" href="<?php echo get_theme_file_uri('/assets/css/swiper.min.css'); ?>">
            <!-- Swiper -->
            <div class="swiper-container">
                <div class="swiper-wrapper">
                    <?php foreach($bannerConf as $_row): ?>
                    <div class="swiper-slide" style="background: url(<?php echo $_row; ?>);"></div>
                    <?php endforeach; ?>
                </div>
                <!-- Add Pagination -->
                <div class="swiper-pagination"></div>
            </div>

            <!-- Swiper JS -->
            <script src="<?php echo get_theme_file_uri('/assets/js/swiper.min.js'); ?>"></script>

            <!-- Initialize Swiper -->
            <script>
                var swiper = new Swiper('.swiper-container', {
                    autoplay: true, //可选选项，自动滑动
                    effect: 'fade',
                    pagination: {
                        el: '.swiper-pagination',
                    }
                });
            </script>
        <?php else : ?>
            <div class="swiper-container">
                <?php
                    $randBanner = rand(0, count($bannerConf) - 1);
                ?>
                <div class="static-banner" style="background: url(<?php echo $bannerConf[$randBanner]; ?>);"></div>
            </div>

            <div class="nav-info-toolbar">
                首页<?php
                    if ('post' === get_post_type()) {
                        if (is_single()) {
                            $thisCat = get_the_category();
                            if (!empty($thisCat)) {
                                $thisCat = $thisCat[0];
                                if ($thisCat->parent) {
                                    $parentCat = get_category($thisCat->parent);
                                    if (!empty($parentCat)) {
                                        echo ' &gt; ' . $parentCat->name;
                                    }
                                }
                                echo ' &gt; ' . $thisCat->name;
                            } 
                            echo ' &gt; ' . get_the_title();
                        } else {
                            $category = get_the_category();
                            if(!empty($category)) {
                                $category = $category[0];
                                if($category->parent) {
                                    $parentCat = get_category($category->parent);
                                    if(!empty($parentCat)) {
                                        echo ' &gt; ' . $parentCat->name;
                                    }
                                }
                                echo ' &gt; ' . $category->name;
                            }                            
                        };
                    } else {
                        if(isset($cat) && !empty($cat)) {
                            $thisCat = get_category($cat);
                            if ($thisCat->parent) {
                                $parentCat = get_category($thisCat->parent);
                                if (!empty($parentCat)) {
                                    echo ' &gt; ' . $parentCat->name;
                                }
                            }
                            if (!empty($thisCat)) {
                                echo ' &gt; ' . $thisCat->name;
                            }
                        } else {
                            echo ' &gt; ' . get_the_title();
                        }
                    };
                    
                    ?>
            </div>
        <?php endif; ?>

        <?php

        /*
	 * If a regular post or page, and not the front page, show the featured image.
	 * Using get_queried_object_id() here since the $post global may not be set before a call to the_post().
	 */
        if ((is_single() || (is_page() && !twentyseventeen_is_frontpage())) && has_post_thumbnail(get_queried_object_id())) :
            echo '<div class="single-featured-image-header">';
            echo get_the_post_thumbnail(get_queried_object_id(), 'twentyseventeen-featured-image');
            echo '</div><!-- .single-featured-image-header -->';
        endif;
        ?>

        <div class="site-content-contain">
            <div id="content" class="site-content">